package com.coment.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.springframework.data.annotation.Id;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

public class LiveData implements Serializable {
    @ToString
    public static class DyPayload {
        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        public static class BaseMsg implements Serializable {
            public String msg_id;

            public String sec_openid;

            public String avatar_url;

            public String nickname;

            public Long timestamp;

            public Boolean test;

            public BaseMsg obtainBaseMsg() {
                return this;
            }
        }


        @Data
        @EqualsAndHashCode(callSuper = true)
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        public static class CommentsMsg extends BaseMsg implements Serializable {
            private String content;
        }

        @Data
        @EqualsAndHashCode(callSuper = true)
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        public static class LiveGiftMsg extends BaseMsg implements Serializable {
            private String sec_gift_id;
            private Integer gift_num;
            private Integer gift_value;
            private String audience_sec_open_id;
        }

        @Data
        @EqualsAndHashCode(callSuper = true)
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        public static class LiveLikeMsg extends BaseMsg implements Serializable {
            private Integer like_num;
        }

        @Data
        @EqualsAndHashCode(callSuper = true)
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        public static class FansClubMsg extends BaseMsg implements Serializable {
            private Integer fansclub_reason_type;
            private Integer fansclub_level;
        }


        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @ToString
        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class AnchorInfo {
            @Id
            private String anchorOpenId;
            private String avatarUrl;
            private String nickName;
            private String roomId;
            private int roundId;
        }
    }


    @Getter
    @AllArgsConstructor
    public enum ApiType {
        douyin("douyin"),
        kuaiShou("kuaiShou");
        private final String value;

        public static ApiType fromValue(String value) {
            for (ApiType type : values()) {
                if (type.getValue().equals(value)) {
                    return type;
                }
            }

            throw new IllegalArgumentException("未知的消息类型:%s, 当前支持的数值%s".formatted(value, Arrays.toString(values())));
        }
    }

    @Data
    @ToString
    public static class KSPayload {
        @JsonProperty("app_id")
        private String appid;

        @JsonProperty("data")
        private KSPayloadData KSPayloadData;

        @JsonProperty("event")
        private String event;

        @JsonProperty("message_id")
        private String messageid;

        @JsonProperty("timestamp")
        private long timestamp;

        @ToString
        @lombok.Data
        public static class KSPayloadData {
            @JsonProperty("author_open_id")
            private String authorOpenid;

            @JsonProperty("live_timestamp")
            private long liveTimestamp;

            private List<Payload> payload;

            @JsonProperty("push_type")
            private String pushType;

            @JsonProperty("room_code")
            private String roomCode;

            @JsonProperty("unique_message_id")
            private String uniqueMessageid;
            @ToString
            @lombok.Data
            public static class Payload {
                private String content;

                private Long count;

                @JsonProperty("gift_count")
                private Long giftCount;

                @JsonProperty("gift_id")
                private String giftId;

                @JsonProperty("gift_name")
                private String giftName;

                @JsonProperty("gift_total_price")
                private Long giftTotalPrice;

                @JsonProperty("gift_unit_price")
                private Long giftUnitPrice;

                @JsonProperty("unique_no")
                private String uniqueNo;

                @JsonProperty("user_info")
                private UserInfo userInfo;

                @ToString
                @lombok.Data
                public static class UserInfo {
                    @JsonProperty("head_url")
                    private String headUrl;

                    @JsonProperty("user_id")
                    private String userId;

                    @JsonProperty("user_name")
                    private String userName;
                }
            }
        }
    }


}
